#include "sdl/sdl.h"
#include "dv_sdlgrafix.h"

int main(int argc, char ** argv)
{
	// [INIT]
	int SCREEN_WIDTH = 800;
	int SCREEN_HEIGHT = 600;
	int SCREEN_BPP = 32;
	// main state of the main loop
	if (SDL_Init( SDL_INIT_VIDEO ) != 0)
		printf( "Unable to init SDL: %s\n", SDL_GetError());
    // ensure a clean exit
    atexit(SDL_Quit);
    // create a new window
    SDL_Surface* screen = 
		SDL_SetVideoMode(
		SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
		SDL_HWSURFACE|SDL_DOUBLEBUF);

	SDL_Rect r = {10, 20, 30, 40};

	SDL_Surface * myImage = load_image("image.bmp");
	SDL_Rect r2 = {0, 0, myImage->w, myImage->h};

	SDL_Event e;
	bool running = true;
	int timer;
	while(running)
	{
		// draw
		SDL_FillRect(screen, &r, 0x00ff88);
		SDL_BlitSurface(myImage, &r2, screen, &r);
		SDL_Flip(screen);

		// throttle code (slows down the CPU)
		timer = SDL_GetTicks() + 1000;
		while(!SDL_PollEvent(0) && SDL_GetTicks() < timer)
		{
			SDL_Delay(1);
		}
		// input
		while(SDL_PollEvent(&e))
		{
			switch(e.type)
			{
			case SDL_QUIT:
				running = false;
				break;
			}
		}
		// update
	}

	SDL_FreeSurface(myImage);
	SDL_FreeSurface(screen);
	SDL_Quit();
	return 0;
}